package com.ourteam.product.api;

import org.apache.commons.lang.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.product.ui.dao.ProductUITabDAOQueryBean;
import com.ourteam.product.ui.domain.ProductUITableBean;

public class ProductUITabSearchModel extends AbstractSearchModel<ProductUITabDAOQueryBean> {

	private Long domainId;

	private String code;

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Long getDomainId() {
		return domainId;
	}

	public void setDomainId(Long domainId) {
		this.domainId = domainId;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return ProductUITableBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(ProductUITabDAOQueryBean queryBean) throws Exception {

		ProductUITabDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (this.domainId != null && this.domainId != 0) {
			criteria.andDomainIdEqualTo(domainId);
		}

		if(StringUtils.isNotBlank(code)) {
			criteria.andCodeLike(code);
		}
	}

}
